<?xml version="1.0" encoding="UTF-8"?>
<?altova_samplexml la_principessa.xml?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:asp="remove" xmlns:ctl="remove" xmlns:tinymce="remove" xmlns:ptl="remove">
	<xsl:output method="xhtml" omit-xml-declaration="yes" />
	<xsl:template match="/">
		<xsl:if test="//root/items/item/name/text()">
        	<xsl:call-template name="TrySons">
            	<xsl:with-param name="sons" select="//root/items"></xsl:with-param>
                <xsl:with-param name="first">1</xsl:with-param>
            </xsl:call-template>
        </xsl:if>
	</xsl:template>
    
    <xsl:template name="TrySons">
    	<xsl:param name="sons"></xsl:param>
        <xsl:param name="first"></xsl:param>
        <ul>
        	<xsl:if test="$first='1'">
            <xsl:attribute name="id"><xsl:value-of select="//root/htmlid" disable-output-escaping="yes"/></xsl:attribute>
            <xsl:attribute name="class">MenuBarHorizontal</xsl:attribute>
            </xsl:if>
            <xsl:for-each select="$sons/item">
                <li>
				<xsl:choose>
                	<xsl:when test="$first='1'">
			            <xsl:attribute name="class">MainHome</xsl:attribute>
                    </xsl:when>
                    <xsl:otherwise>
			            <xsl:attribute name="class">MenuBarItemSubmenu</xsl:attribute>
                    </xsl:otherwise>
                </xsl:choose>                
                <xsl:attribute name="id"><xsl:value-of select="unique"></xsl:value-of>_<xsl:value-of select="translate(name,' ','')"/></xsl:attribute>
                <xsl:attribute name="class"><xsl:value-of select="class"></xsl:value-of></xsl:attribute>  
                <xsl:variable name="linker">
                    <xsl:choose>
                        <xsl:when test="contains(link,'?')">&amp;idc=<xsl:value-of select="idcomp"></xsl:value-of>&amp;idi=<xsl:value-of select="idmod"></xsl:value-of></xsl:when>
                        <xsl:otherwise>?idc=<xsl:value-of select="idcomp"></xsl:value-of>&amp;idi=<xsl:value-of select="idmod"></xsl:value-of></xsl:otherwise>
                    </xsl:choose>
                </xsl:variable>       
                        <a href="{link}{$linker}" title="{name}">   
                <xsl:if test="img/text()">
                	<xsl:choose>
                	<xsl:when test="idcomp='-1'">
	                	<img src="/administration/template/admimg/{img}" alt="{name}" style="border:0px;" />
                    </xsl:when>
                    <xsl:otherwise>
	                	<img src="/controls/{../../componentpath}/{img}" alt="{name}" style="border:0px;" />
                    </xsl:otherwise>
                    </xsl:choose>
                </xsl:if>
                <xsl:value-of select="name"></xsl:value-of>
                </a>
                
                <xsl:if test="./items/item/name/text()">
                    <xsl:call-template name="TrySons">
                        <xsl:with-param name="sons" select="./items"></xsl:with-param>
                        <xsl:with-param name="fist">0</xsl:with-param>
                    </xsl:call-template>
                </xsl:if>
                </li>
            </xsl:for-each>
        </ul>        
    </xsl:template>
</xsl:stylesheet>